<html>
 <head>
  <meta charset="utf-8"/>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"/>
  <title>
   使用python爬虫抓站的一些技巧总结：进阶篇  | 数螺 | NAUT IDEA
  </title>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" rel="stylesheet"/>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
  <style type="text/css">
   #xmain img {
                  max-width: 100%;
                  display: block;
                  margin-top: 10px;
                  margin-bottom: 10px;
                }

                #xmain p {
                    line-height:150%;
                    font-size: 16px;
                    margin-top: 20px;
                }

                #xmain h2 {
                    font-size: 24px;
                }

                #xmain h3 {
                    font-size: 20px;
                }

                #xmain h4 {
                    font-size: 18px;
                }


                .header {
	           background-color: #0099ff;
	           color: #ffffff;
	           margin-bottom: 20px;
	        }

	        .header p {
                  margin: 0px;
                  padding: 10px 0;
                  display: inline-block;  
                  vertical-align: middle;
                  font-size: 16px;
               }

               .header a {
                 color: white;
               }

              .header img {
                 height: 25px;
              }
  </style>
  <script src="http://cdn.bootcss.com/jquery/3.0.0/jquery.min.js">
  </script>
  <script src="http://nautstatic-10007657.file.myqcloud.com/static/css/readability.min.js" type="text/javascript">
  </script>
  <script type="text/javascript">
   $(document).ready(function() {
                 var loc = document.location;
                 var uri = {
                  spec: "http://dataunion.org/5230.html",
                  host: "http://dataunion.org",
                  prePath: "http://dataunion.org",
                  scheme: "http",
                  pathBase: "http://dataunion.org/"
                 };
    
                 var documentClone = document.cloneNode(true);
                 var article = new Readability(uri, documentClone).parse();
     
                 document.getElementById("xmain").innerHTML = article.content;
                });
  </script>
  <!-- 1466459569: Accept with keywords: (title(0.285714285714):总结,社区,技巧,python,数盟,爬虫,进阶篇, topn(0.2):社区,队列,解压缩,数盟,代理,行业资讯,任务,最终版,数据挖掘,总结,Python,职业规划,进阶篇,基础架构,文章,服务器,方法,网页,python,批量,东东,可视化,时需,异步,技巧,编程语言,程序,爬虫,解构,线程).-->
 </head>
 <body onload="">
  <div class="header">
   <div class="container">
    <div class="row">
     <div class="col-xs-6 col-sm-6 text-left">
      <a href="/databee">
       <img src="http://nautidea-10007657.cos.myqcloud.com/logo_white.png"/>
      </a>
      <a href="/databee">
       <p>
        数螺
       </p>
      </a>
     </div>
     <div class="hidden-xs col-sm-6 text-right">
      <p>
       致力于数据科学的推广和知识传播
      </p>
     </div>
    </div>
   </div>
  </div>
  <div class="container text-center">
   <h1>
    使用python爬虫抓站的一些技巧总结：进阶篇
   </h1>
  </div>
  <div class="container" id="xmain">
   ﻿﻿
   <title>
    使用python爬虫抓站的一些技巧总结：进阶篇 | 数盟社区
   </title>
   <!-- All in One SEO Pack 2.2.7.6.2 by Michael Torbert of Semper Fi Web Design[32,70] -->
   <!-- /all in one seo pack -->
   <!--
<div align="center">
<a href="http://strata.oreilly.com.cn/hadoop-big-data-cn?cmp=mp-data-confreg-home-stcn16_dataunion_pc" target="_blank"><img src="http://dataunion.org/wp-content/uploads/2016/05/stratabj.jpg"/ ></a>
</div>
-->
   <header id="header-web">
    <div class="header-main">
     <hgroup class="logo">
      <h1>
       <a href="http://dataunion.org/" rel="home" title="数盟社区">
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/logo.png"/>
       </a>
      </h1>
     </hgroup>
     <!--logo-->
     <nav class="header-nav">
      <ul class="menu" id="menu-%e4%b8%bb%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-71" id="menu-item-71">
        <a href="http://dataunion.org/category/events" title="events">
         活动
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22457" id="menu-item-22457">
          <a href="http://dataunion.org/2016timeline">
           2016档期
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22459" id="menu-item-22459">
          <a href="http://dataunion.org/category/parterc">
           合作会议
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category current-post-ancestor current-menu-parent current-post-parent menu-item-has-children menu-item-20869" id="menu-item-20869">
        <a href="http://dataunion.org/category/tech" title="articles">
         文章
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20867" id="menu-item-20867">
          <a href="http://dataunion.org/category/tech/base" title="base">
           基础架构
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3302" id="menu-item-3302">
          <a href="http://dataunion.org/category/tech/ai" title="ai">
           人工智能
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3303" id="menu-item-3303">
          <a href="http://dataunion.org/category/tech/analysis" title="analysis">
           数据分析
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21920" id="menu-item-21920">
          <a href="http://dataunion.org/category/tech/dm">
           数据挖掘
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3314" id="menu-item-3314">
          <a href="http://dataunion.org/category/tech/viz" title="viz">
           可视化
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category current-post-ancestor current-menu-parent current-post-parent menu-item-3305" id="menu-item-3305">
          <a href="http://dataunion.org/category/tech/devl" title="devl">
           编程语言
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-20876" id="menu-item-20876">
        <a href="http://dataunion.org/category/industry">
         行业
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-16328" id="menu-item-16328">
          <a href="http://dataunion.org/category/industry/case" title="case">
           行业应用
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-2112" id="menu-item-2112">
          <a href="http://dataunion.org/category/industry/demo" title="demo">
           Demo展示
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21562" id="menu-item-21562">
          <a href="http://dataunion.org/category/industry/news">
           行业资讯
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-311" id="menu-item-311">
        <a href="http://dataunion.org/category/sources" title="sources">
         资源
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20870" id="menu-item-20870">
        <a href="http://dataunion.org/category/books" title="book">
         图书
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21363" id="menu-item-21363">
        <a href="http://dataunion.org/category/training">
         课程
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-21853" id="menu-item-21853">
        <a href="http://dataunion.org/category/jobs">
         职位
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22050" id="menu-item-22050">
          <a href="http://dataunion.org/category/career">
           职业规划
          </a>
         </li>
        </ul>
       </li>
      </ul>
     </nav>
     <!--header-nav-->
    </div>
   </header>
   <!--header-web-->
   <div id="main">
    <div id="soutab">
     <form action="http://dataunion.org/" class="search" method="get">
     </form>
    </div>
    <div id="container">
     <nav id="mbx">
      当前位置：
      <a href="http://dataunion.org">
       首页
      </a>
      &gt;
      <a href="http://dataunion.org/category/tech">
       文章
      </a>
      &gt;  正文
     </nav>
     <!--mbx-->
     <article class="content">
      <header align="centre" class="contenttitle">
       <div class="mscc">
        <h1 class="mscctitle">
         <a href="http://dataunion.org/5230.html">
          使用python爬虫抓站的一些技巧总结：进阶篇
         </a>
        </h1>
        <address class="msccaddress ">
         <em>
          2,977 次阅读 -
         </em>
         <a href="http://dataunion.org/category/tech" rel="category tag">
          文章
         </a>
         ,
         <a href="http://dataunion.org/category/tech/devl" rel="category tag">
          编程语言
         </a>
        </address>
       </div>
      </header>
      <div class="content-text">
       <p>
        以前写过一篇
        <a href="http://dataunion.org/?p=5225">
         <span style="color: #0066cc;">
          使用python爬虫抓站的一些技巧总结
         </span>
        </a>
        ，总结了诸多爬虫使用的方法；那篇东东现在看来还是挺有用的，但是当时很菜（现在也菜，但是比那时进步了不少），很多东西都不是很优，属于”只是能用”这么个层次。这篇进阶篇打算把“能用”提升到“用得省事省心”这个层次。
       </p>
       <h2>
        <span style="font-size: x-large;">
         一、gzip/deflate支持
        </span>
       </h2>
       <p>
        <span id="more-753">
        </span>
        现在的网页普遍支持gzip压缩，这往往可以解决大量传输时间，以VeryCD的主页为例，未压缩版本247K，压缩了以后45K，为原来的1/5。这就意味着抓取速度会快5倍。
       </p>
       <p>
        然而python的urllib/urllib2默认都不支持压缩，要返回压缩格式，必须在request的header里面写明’accept-encoding’，然后读取response后更要检查header查看是否有’content-encoding’一项来判断是否需要解码，很繁琐琐碎。如何让urllib2自动支持gzip, defalte呢？
       </p>
       <p>
        其实可以继承BaseHanlder类，然后build_opener的方式来处理：
       </p>
       <div class="wp_syntax">
        <div class="code">
         <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
         <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-5768659bc8041118413033" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
          <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <span class="crayon-title">
           </span>
           <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
            <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-wrap-button" title="切换自动换行">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-expand-button" title="点击展开代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-copy-button" title="复制代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
           </div>
          </div>
          <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
          </div>
          <div class="crayon-plain-wrap">
           <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
            import urllib2
from gzip import GzipFile
from StringIO import StringIO
class ContentEncodingProcessor(urllib2.BaseHandler):
  """A handler to add gzip capabilities to urllib2 requests """
 
  # add headers to requests
  def http_request(self, req):
    req.add_header("Accept-Encoding", "gzip, deflate")
    return req
 
  # decode
  def http_response(self, req, resp):
    old_resp = resp
    # gzip
    if resp.headers.get("content-encoding") == "gzip":
        gz = GzipFile(
                    fileobj=StringIO(resp.read()),
                    mode="r"
                  )
        resp = urllib2.addinfourl(gz, old_resp.headers, old_resp.url, old_resp.code)
        resp.msg = old_resp.msg
    # deflate
    if resp.headers.get("content-encoding") == "deflate":
        gz = StringIO( deflate(resp.read()) )
        resp = urllib2.addinfourl(gz, old_resp.headers, old_resp.url, old_resp.code)  # 'class to add info() and
        resp.msg = old_resp.msg
    return resp
 
# deflate support
import zlib
def deflate(data):   # zlib only provides the zlib compress format, not the deflate format;
  try:               # so on top of all there's this workaround:
    return zlib.decompress(data, -zlib.MAX_WBITS)
  except zlib.error:
    return zlib.decompress(data)
           </textarea>
          </div>
          <div class="crayon-main" style="">
           <table class="crayon-table">
            <tbody>
             <tr class="crayon-row">
              <td class="crayon-nums " data-settings="show">
               <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                <div class="crayon-num" data-line="crayon-5768659bc8041118413033-1">
                 1
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8041118413033-2">
                 2
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8041118413033-3">
                 3
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8041118413033-4">
                 4
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8041118413033-5">
                 5
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8041118413033-6">
                 6
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8041118413033-7">
                 7
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8041118413033-8">
                 8
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8041118413033-9">
                 9
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8041118413033-10">
                 10
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8041118413033-11">
                 11
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8041118413033-12">
                 12
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8041118413033-13">
                 13
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8041118413033-14">
                 14
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8041118413033-15">
                 15
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8041118413033-16">
                 16
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8041118413033-17">
                 17
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8041118413033-18">
                 18
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8041118413033-19">
                 19
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8041118413033-20">
                 20
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8041118413033-21">
                 21
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8041118413033-22">
                 22
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8041118413033-23">
                 23
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8041118413033-24">
                 24
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8041118413033-25">
                 25
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8041118413033-26">
                 26
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8041118413033-27">
                 27
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8041118413033-28">
                 28
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8041118413033-29">
                 29
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8041118413033-30">
                 30
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8041118413033-31">
                 31
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8041118413033-32">
                 32
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8041118413033-33">
                 33
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8041118413033-34">
                 34
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8041118413033-35">
                 35
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8041118413033-36">
                 36
                </div>
               </div>
              </td>
              <td class="crayon-code">
               <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                <div class="crayon-line" id="crayon-5768659bc8041118413033-1">
                 <span class="crayon-e">
                  import
                 </span>
                 <span class="crayon-e">
                  urllib2
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8041118413033-2">
                 <span class="crayon-e">
                  from
                 </span>
                 <span class="crayon-e">
                  gzip
                 </span>
                 <span class="crayon-e">
                  import
                 </span>
                 <span class="crayon-e">
                  GzipFile
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8041118413033-3">
                 <span class="crayon-e">
                  from
                 </span>
                 <span class="crayon-e">
                  StringIO
                 </span>
                 <span class="crayon-e">
                  import
                 </span>
                 <span class="crayon-e">
                  StringIO
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8041118413033-4">
                 <span class="crayon-t">
                  class
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  ContentEncodingProcessor
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  urllib2
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  BaseHandler
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8041118413033-5">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  ""
                 </span>
                 <span class="crayon-s">
                  "A handler to add gzip capabilities to urllib2 requests "
                 </span>
                 <span class="crayon-s">
                  ""
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8041118413033-6">
                </div>
                <div class="crayon-line" id="crayon-5768659bc8041118413033-7">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-p">
                  # add headers to requests
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8041118413033-8">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  def
                 </span>
                 <span class="crayon-e">
                  http_request
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  req
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8041118413033-9">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  req
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  add_header
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-s">
                  "Accept-Encoding"
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  "gzip, deflate"
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8041118413033-10">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  return
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-i">
                  req
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8041118413033-11">
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8041118413033-12">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-p">
                  # decode
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8041118413033-13">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  def
                 </span>
                 <span class="crayon-e">
                  http_response
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  req
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  resp
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8041118413033-14">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  old_resp
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  resp
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8041118413033-15">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-p">
                  # gzip
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8041118413033-16">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  if
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  resp
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  headers
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  get
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-s">
                  "content-encoding"
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  ==
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  "gzip"
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8041118413033-17">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  gz
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  GzipFile
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8041118413033-18">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  fileobj
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-e">
                  StringIO
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  resp
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  read
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8041118413033-19">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  mode
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-s">
                  "r"
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8041118413033-20">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8041118413033-21">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  resp
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  urllib2
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  addinfourl
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  gz
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  old_resp
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  headers
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  old_resp
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  url
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  old_resp
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  code
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8041118413033-22">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  resp
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  msg
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  old_resp
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  msg
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8041118413033-23">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-p">
                  # deflate
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8041118413033-24">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  if
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  resp
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  headers
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  get
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-s">
                  "content-encoding"
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  ==
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  "deflate"
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8041118413033-25">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  gz
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  StringIO
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  deflate
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  resp
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  read
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8041118413033-26">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  resp
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  urllib2
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  addinfourl
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  gz
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  old_resp
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  headers
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  old_resp
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  url
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  old_resp
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  code
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-p">
                  # 'class to add info() and
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8041118413033-27">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  resp
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  msg
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  old_resp
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  msg
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8041118413033-28">
                 <span class="crayon-e">
                 </span>
                 <span class="crayon-st">
                  return
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-i">
                  resp
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8041118413033-29">
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8041118413033-30">
                 <span class="crayon-p">
                  # deflate support
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8041118413033-31">
                 <span class="crayon-e">
                  import
                 </span>
                 <span class="crayon-e">
                  zlib
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8041118413033-32">
                 <span class="crayon-e">
                  def
                 </span>
                 <span class="crayon-e">
                  deflate
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  data
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-p">
                  # zlib only provides the zlib compress format, not the deflate format;
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8041118413033-33">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  try
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-p">
                  # so on top of all there's this workaround:
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8041118413033-34">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  return
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  zlib
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  decompress
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  data
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  -
                 </span>
                 <span class="crayon-v">
                  zlib
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  MAX_WBITS
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8041118413033-35">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  except
                 </span>
                 <span class="crayon-v">
                  zlib
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  error
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8041118413033-36">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  return
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  zlib
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  decompress
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  data
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
               </div>
              </td>
             </tr>
            </tbody>
           </table>
          </div>
         </div>
         <!-- [Format Time: 0.0380 seconds] -->
        </div>
       </div>
       <p>
        然后就简单了，
       </p>
       <div class="wp_syntax">
        <div class="code">
         <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
         <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-5768659bc8057283384863" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
          <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <span class="crayon-title">
           </span>
           <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
            <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-wrap-button" title="切换自动换行">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-expand-button" title="点击展开代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-copy-button" title="复制代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
           </div>
          </div>
          <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
          </div>
          <div class="crayon-plain-wrap">
           <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
            encoding_support = ContentEncodingProcessor
opener = urllib2.build_opener( encoding_support, urllib2.HTTPHandler )
 
#直接用opener打开网页，如果服务器支持gzip/defalte则自动解压缩
content = opener.open(url).read()
           </textarea>
          </div>
          <div class="crayon-main" style="">
           <table class="crayon-table">
            <tbody>
             <tr class="crayon-row">
              <td class="crayon-nums " data-settings="show">
               <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                <div class="crayon-num" data-line="crayon-5768659bc8057283384863-1">
                 1
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8057283384863-2">
                 2
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8057283384863-3">
                 3
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8057283384863-4">
                 4
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8057283384863-5">
                 5
                </div>
               </div>
              </td>
              <td class="crayon-code">
               <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                <div class="crayon-line" id="crayon-5768659bc8057283384863-1">
                 <span class="crayon-v">
                  encoding_support
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  ContentEncodingProcessor
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8057283384863-2">
                 <span class="crayon-v">
                  opener
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  urllib2
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  build_opener
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  encoding_support
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  urllib2
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-i">
                  HTTPHandler
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8057283384863-3">
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8057283384863-4">
                 <span class="crayon-p">
                  #直接用opener打开网页，如果服务器支持gzip/defalte则自动解压缩
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8057283384863-5">
                 <span class="crayon-v">
                  content
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  opener
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  open
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  url
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  read
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
               </div>
              </td>
             </tr>
            </tbody>
           </table>
          </div>
         </div>
         <!-- [Format Time: 0.0109 seconds] -->
        </div>
       </div>
       <h2>
        <span style="font-size: x-large;">
         二、更方便地多线程
        </span>
       </h2>
       <p>
        总结一文的确提及了一个简单的多线程模板，但是那个东东真正应用到程序里面去只会让程序变得支离破碎，不堪入目。在怎么更方便地进行多线程方面我也动了一番脑筋。先想想怎么进行多线程调用最方便呢？
       </p>
       <h3>
        <strong>
         1、用twisted进行异步I/O抓取
        </strong>
       </h3>
       <p>
        事实上更高效的抓取并非一定要用多线程，也可以使用异步I/O法：直接用twisted的getPage方法，然后分别加上异步I/O结束时的callback和errback方法即可。例如可以这么干：
       </p>
       <div class="wp_syntax">
        <div class="code">
         <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
         <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-5768659bc805f491704935" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
          <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <span class="crayon-title">
           </span>
           <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
            <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-wrap-button" title="切换自动换行">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-expand-button" title="点击展开代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-copy-button" title="复制代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
           </div>
          </div>
          <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
          </div>
          <div class="crayon-plain-wrap">
           <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
            from twisted.web.client import getPage
from twisted.internet import reactor
 
links = [ 'http://www.verycd.com/topics/%d/'%i for i in range(5420,5430) ]
 
def parse_page(data,url):
    print len(data),url
 
def fetch_error(error,url):
    print error.getErrorMessage(),url
 
# 批量抓取链接
for url in links:
    getPage(url,timeout=5) \
        .addCallback(parse_page,url) \ #成功则调用parse_page方法
        .addErrback(fetch_error,url)     #失败则调用fetch_error方法
 
reactor.callLater(5, reactor.stop) #5秒钟后通知reactor结束程序
reactor.run()
           </textarea>
          </div>
          <div class="crayon-main" style="">
           <table class="crayon-table">
            <tbody>
             <tr class="crayon-row">
              <td class="crayon-nums " data-settings="show">
               <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                <div class="crayon-num" data-line="crayon-5768659bc805f491704935-1">
                 1
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc805f491704935-2">
                 2
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc805f491704935-3">
                 3
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc805f491704935-4">
                 4
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc805f491704935-5">
                 5
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc805f491704935-6">
                 6
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc805f491704935-7">
                 7
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc805f491704935-8">
                 8
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc805f491704935-9">
                 9
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc805f491704935-10">
                 10
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc805f491704935-11">
                 11
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc805f491704935-12">
                 12
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc805f491704935-13">
                 13
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc805f491704935-14">
                 14
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc805f491704935-15">
                 15
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc805f491704935-16">
                 16
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc805f491704935-17">
                 17
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc805f491704935-18">
                 18
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc805f491704935-19">
                 19
                </div>
               </div>
              </td>
              <td class="crayon-code">
               <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                <div class="crayon-line" id="crayon-5768659bc805f491704935-1">
                 <span class="crayon-e">
                  from
                 </span>
                 <span class="crayon-v">
                  twisted
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  web
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  client
                 </span>
                 <span class="crayon-e">
                  import
                 </span>
                 <span class="crayon-e">
                  getPage
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc805f491704935-2">
                 <span class="crayon-e">
                  from
                 </span>
                 <span class="crayon-v">
                  twisted
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  internet
                 </span>
                 <span class="crayon-e">
                  import
                 </span>
                 <span class="crayon-i">
                  reactor
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc805f491704935-3">
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc805f491704935-4">
                 <span class="crayon-v">
                  links
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-sy">
                  [
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'http://www.verycd.com/topics/%d/'
                 </span>
                 <span class="crayon-o">
                  %
                 </span>
                 <span class="crayon-i">
                  i
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  for
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-i">
                  i
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  in
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  range
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-cn">
                  5420
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-cn">
                  5430
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-sy">
                  ]
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc805f491704935-5">
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc805f491704935-6">
                 <span class="crayon-e">
                  def
                 </span>
                 <span class="crayon-e">
                  parse_page
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  data
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-v">
                  url
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc805f491704935-7">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  print
                 </span>
                 <span class="crayon-e">
                  len
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  data
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-i">
                  url
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc805f491704935-8">
                </div>
                <div class="crayon-line" id="crayon-5768659bc805f491704935-9">
                 <span class="crayon-e">
                  def
                 </span>
                 <span class="crayon-e">
                  fetch_error
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  error
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-v">
                  url
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc805f491704935-10">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  print
                 </span>
                 <span class="crayon-v">
                  error
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  getErrorMessage
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-i">
                  url
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc805f491704935-11">
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc805f491704935-12">
                 <span class="crayon-p">
                  # 批量抓取链接
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc805f491704935-13">
                 <span class="crayon-st">
                  for
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  url
                 </span>
                 <span class="crayon-st">
                  in
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  links
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc805f491704935-14">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  getPage
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  url
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-v">
                  timeout
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-cn">
                  5
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-sy">
                  \
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc805f491704935-15">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  addCallback
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  parse_page
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-v">
                  url
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-sy">
                  \
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-p">
                  #成功则调用parse_page方法
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc805f491704935-16">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  addErrback
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  fetch_error
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-v">
                  url
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-p">
                  #失败则调用fetch_error方法
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc805f491704935-17">
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc805f491704935-18">
                 <span class="crayon-v">
                  reactor
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  callLater
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-cn">
                  5
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  reactor
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  stop
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-p">
                  #5秒钟后通知reactor结束程序
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc805f491704935-19">
                 <span class="crayon-v">
                  reactor
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  run
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
               </div>
              </td>
             </tr>
            </tbody>
           </table>
          </div>
         </div>
         <!-- [Format Time: 0.0177 seconds] -->
        </div>
       </div>
       <p>
        twisted人如其名，写的代码实在是太扭曲了，非正常人所能接受，虽然这个简单的例子看上去还好；每次写twisted的程序整个人都扭曲了，累得不得了，文档等于没有，必须得看源码才知道怎么整，唉不提了。
       </p>
       <p>
        如果要支持gzip/deflate，甚至做一些登陆的扩展，就得为twisted写个新的HTTPClientFactory类诸如此类，我这眉头真是大皱，遂放弃。有毅力者请自行尝试。
       </p>
       <p>
        这篇讲
        <a href="http://oubiwann.blogspot.com/2008/06/async-batching-with-twisted-walkthrough.html">
         <span style="color: #0066cc;">
          怎么用twisted来进行批量网址处理
         </span>
        </a>
        的文章不错，由浅入深，深入浅出，可以一看。
       </p>
       <h3>
        <strong>
         2、设计一个简单的多线程抓取类
        </strong>
       </h3>
       <p>
        还是觉得在urllib之类python“本土”的东东里面折腾起来更舒服。试想一下，如果有个Fetcher类，你可以这么调用
       </p>
       <div class="wp_syntax">
        <div class="code">
         <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
         <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-5768659bc8067370077424" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
          <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <span class="crayon-title">
           </span>
           <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
            <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-wrap-button" title="切换自动换行">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-expand-button" title="点击展开代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-copy-button" title="复制代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
           </div>
          </div>
          <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
          </div>
          <div class="crayon-plain-wrap">
           <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
            f = Fetcher(threads=10) #设定下载线程数为10
for url in urls:
    f.push(url)  #把所有url推入下载队列
while f.taskleft(): #若还有未完成下载的线程
    content = f.pop()  #从下载完成队列中取出结果
    do_with(content) # 处理content内容
           </textarea>
          </div>
          <div class="crayon-main" style="">
           <table class="crayon-table">
            <tbody>
             <tr class="crayon-row">
              <td class="crayon-nums " data-settings="show">
               <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                <div class="crayon-num" data-line="crayon-5768659bc8067370077424-1">
                 1
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8067370077424-2">
                 2
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8067370077424-3">
                 3
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8067370077424-4">
                 4
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8067370077424-5">
                 5
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8067370077424-6">
                 6
                </div>
               </div>
              </td>
              <td class="crayon-code">
               <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                <div class="crayon-line" id="crayon-5768659bc8067370077424-1">
                 <span class="crayon-v">
                  f
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  Fetcher
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  threads
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-cn">
                  10
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-p">
                  #设定下载线程数为10
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8067370077424-2">
                 <span class="crayon-st">
                  for
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  url
                 </span>
                 <span class="crayon-st">
                  in
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  urls
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8067370077424-3">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  f
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  push
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  url
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-p">
                  #把所有url推入下载队列
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8067370077424-4">
                 <span class="crayon-st">
                  while
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  f
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  taskleft
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-p">
                  #若还有未完成下载的线程
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8067370077424-5">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  content
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  f
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  pop
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-p">
                  #从下载完成队列中取出结果
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8067370077424-6">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  do_with
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  content
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-p">
                  # 处理content内容
                 </span>
                </div>
               </div>
              </td>
             </tr>
            </tbody>
           </table>
          </div>
         </div>
         <!-- [Format Time: 0.0105 seconds] -->
        </div>
       </div>
       <p>
        这么个多线程调用简单明了，那么就这么设计吧，首先要有两个队列，用Queue搞定，多线程的基本架构也和“技巧总结”一文类似，push方法和pop方法都比较好处理，都是直接用Queue的方法，taskleft则是如果有“正在运行的任务”或者”队列中的任务”则为是，也好办，于是代码如下：
       </p>
       <div class="wp_syntax">
        <div class="code">
         <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
         <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-5768659bc8071911625247" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
          <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <span class="crayon-title">
           </span>
           <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
            <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-wrap-button" title="切换自动换行">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-expand-button" title="点击展开代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-copy-button" title="复制代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
           </div>
          </div>
          <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
          </div>
          <div class="crayon-plain-wrap">
           <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
            import urllib2
from threading import Thread,Lock
from Queue import Queue
import time
 
class Fetcher:
    def __init__(self,threads):
        self.opener = urllib2.build_opener(urllib2.HTTPHandler)
        self.lock = Lock() #线程锁
        self.q_req = Queue() #任务队列
        self.q_ans = Queue() #完成队列
        self.threads = threads
        for i in range(threads):
            t = Thread(target=self.threadget)
            t.setDaemon(True)
            t.start()
        self.running = 0
 
    def __del__(self): #解构时需等待两个队列完成
        time.sleep(0.5)
        self.q_req.join()
        self.q_ans.join()
 
    def taskleft(self):
        return self.q_req.qsize()+self.q_ans.qsize()+self.running
 
    def push(self,req):
        self.q_req.put(req)
 
    def pop(self):
        return self.q_ans.get()
 
    def threadget(self):
        while True:
            req = self.q_req.get()
            with self.lock: #要保证该操作的原子性，进入critical area
                self.running += 1
            try:
                ans = self.opener.open(req).read()
            except Exception, what:
                ans = ''
                print what
            self.q_ans.put((req,ans))
            with self.lock:
                self.running -= 1
            self.q_req.task_done()
            time.sleep(0.1) # don't spam
 
if __name__ == "__main__":
    links = [ 'http://www.verycd.com/topics/%d/'%i for i in range(5420,5430) ]
    f = Fetcher(threads=10)
    for url in links:
        f.push(url)
    while f.taskleft():
        url,content = f.pop()
        print url,len(content)
           </textarea>
          </div>
          <div class="crayon-main" style="">
           <table class="crayon-table">
            <tbody>
             <tr class="crayon-row">
              <td class="crayon-nums " data-settings="show">
               <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-1">
                 1
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-2">
                 2
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-3">
                 3
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-4">
                 4
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-5">
                 5
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-6">
                 6
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-7">
                 7
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-8">
                 8
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-9">
                 9
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-10">
                 10
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-11">
                 11
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-12">
                 12
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-13">
                 13
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-14">
                 14
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-15">
                 15
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-16">
                 16
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-17">
                 17
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-18">
                 18
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-19">
                 19
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-20">
                 20
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-21">
                 21
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-22">
                 22
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-23">
                 23
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-24">
                 24
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-25">
                 25
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-26">
                 26
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-27">
                 27
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-28">
                 28
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-29">
                 29
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-30">
                 30
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-31">
                 31
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-32">
                 32
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-33">
                 33
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-34">
                 34
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-35">
                 35
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-36">
                 36
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-37">
                 37
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-38">
                 38
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-39">
                 39
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-40">
                 40
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-41">
                 41
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-42">
                 42
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-43">
                 43
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-44">
                 44
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-45">
                 45
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-46">
                 46
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-47">
                 47
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-48">
                 48
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-49">
                 49
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-50">
                 50
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-51">
                 51
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-52">
                 52
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-53">
                 53
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-54">
                 54
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8071911625247-55">
                 55
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8071911625247-56">
                 56
                </div>
               </div>
              </td>
              <td class="crayon-code">
               <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                <div class="crayon-line" id="crayon-5768659bc8071911625247-1">
                 <span class="crayon-e">
                  import
                 </span>
                 <span class="crayon-e">
                  urllib2
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-2">
                 <span class="crayon-e">
                  from
                 </span>
                 <span class="crayon-e">
                  threading
                 </span>
                 <span class="crayon-e">
                  import
                 </span>
                 <span class="crayon-v">
                  Thread
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-e">
                  Lock
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-3">
                 <span class="crayon-e">
                  from
                 </span>
                 <span class="crayon-e">
                  Queue
                 </span>
                 <span class="crayon-e">
                  import
                 </span>
                 <span class="crayon-e">
                  Queue
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-4">
                 <span class="crayon-e">
                  import
                 </span>
                 <span class="crayon-i">
                  time
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-5">
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-6">
                 <span class="crayon-t">
                  class
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  Fetcher
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-7">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  def
                 </span>
                 <span class="crayon-e">
                  __init__
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-v">
                  threads
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-8">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  opener
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  urllib2
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  build_opener
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  urllib2
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  HTTPHandler
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-9">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  lock
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  Lock
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-p">
                  #线程锁
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-10">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  q_req
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  Queue
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-p">
                  #任务队列
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-11">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  q_ans
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  Queue
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-p">
                  #完成队列
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-12">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  threads
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  threads
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-13">
                 <span class="crayon-e">
                 </span>
                 <span class="crayon-st">
                  for
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-i">
                  i
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  in
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  range
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  threads
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-14">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  t
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  Thread
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  target
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  threadget
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-15">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  t
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  setDaemon
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-t">
                  True
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-16">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  t
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  start
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-17">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  running
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-cn">
                  0
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-18">
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-19">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  def
                 </span>
                 <span class="crayon-e">
                  __del__
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-p">
                  #解构时需等待两个队列完成
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-20">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  time
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  sleep
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-cn">
                  0.5
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-21">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  q_req
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  join
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-22">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  q_ans
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  join
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-23">
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-24">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  def
                 </span>
                 <span class="crayon-e">
                  taskleft
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-25">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  return
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  q_req
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  qsize
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  +
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  q_ans
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  qsize
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  +
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-i">
                  running
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-26">
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-27">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  def
                 </span>
                 <span class="crayon-e">
                  push
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-v">
                  req
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-28">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  q_req
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  put
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  req
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-29">
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-30">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  def
                 </span>
                 <span class="crayon-e">
                  pop
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-31">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  return
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  q_ans
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  get
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-32">
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-33">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  def
                 </span>
                 <span class="crayon-e">
                  threadget
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-34">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  while
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-t">
                  True
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-35">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  req
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  q_req
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  get
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-36">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  with
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  lock
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-p">
                  #要保证该操作的原子性，进入critical area
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-37">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  running
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  +=
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-cn">
                  1
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-38">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  try
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-39">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  ans
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  opener
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  open
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  req
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  read
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-40">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  except
                 </span>
                 <span class="crayon-v">
                  Exception
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  what
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-41">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  ans
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  ''
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-42">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  print
                 </span>
                 <span class="crayon-e">
                  what
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-43">
                 <span class="crayon-e">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  q_ans
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  put
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  req
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-v">
                  ans
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-44">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  with
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  lock
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-45">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  running
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  -=
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-cn">
                  1
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-46">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  q_req
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  task_done
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-47">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  time
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  sleep
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-cn">
                  0.1
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-p">
                  # don't spam
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-48">
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-49">
                 <span class="crayon-st">
                  if
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  __name__
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  ==
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  "__main__"
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-50">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  links
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-sy">
                  [
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'http://www.verycd.com/topics/%d/'
                 </span>
                 <span class="crayon-o">
                  %
                 </span>
                 <span class="crayon-i">
                  i
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  for
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-i">
                  i
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  in
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  range
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-cn">
                  5420
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-cn">
                  5430
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-sy">
                  ]
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-51">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  f
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  Fetcher
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  threads
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-cn">
                  10
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-52">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  for
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  url
                 </span>
                 <span class="crayon-st">
                  in
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  links
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-53">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  f
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  push
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  url
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-54">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  while
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  f
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  taskleft
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8071911625247-55">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  url
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-v">
                  content
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  f
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  pop
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8071911625247-56">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  print
                 </span>
                 <span class="crayon-v">
                  url
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-e">
                  len
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  content
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
               </div>
              </td>
             </tr>
            </tbody>
           </table>
          </div>
         </div>
         <!-- [Format Time: 0.0501 seconds] -->
        </div>
       </div>
       <h2>
        <span style="font-size: x-large;">
         三、一些琐碎的经验
        </span>
       </h2>
       <h3>
        <strong>
         1、连接池：
        </strong>
       </h3>
       <p>
        opener.open和urllib2.urlopen一样，都会新建一个http请求。通常情况下这不是什么问题，因为线性环境下，一秒钟可能也就新生成一个请求；然而在多线程环境下，每秒钟可以是几十上百个请求，这么干只要几分钟，正常的有理智的服务器一定会封禁你的。
       </p>
       <p>
        然而在正常的html请求时，保持同时和服务器几十个连接又是很正常的一件事，所以完全可以手动维护一个HttpConnection的池，然后每次抓取时从连接池里面选连接进行连接即可。
       </p>
       <p>
        这里有一个取巧的方法，就是利用squid做代理服务器来进行抓取，则squid会自动为你维护连接池，还附带数据缓存功能，而且squid本来就是我每个服务器上面必装的东东，何必再自找麻烦写连接池呢。
       </p>
       <h3>
        <strong>
         2、设定线程的栈大小
        </strong>
       </h3>
       <p>
        栈大小的设定将非常显著地影响python的内存占用，python多线程不设置这个值会导致程序占用大量内存，这对openvz的vps来说非常致命。stack_size必须大于32768，实际上应该总要32768*2以上
       </p>
       <div class="wp_syntax">
        <div class="code">
         <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
         <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-5768659bc807a569365508" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
          <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <span class="crayon-title">
           </span>
           <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
            <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-wrap-button" title="切换自动换行">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-expand-button" title="点击展开代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-copy-button" title="复制代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
           </div>
          </div>
          <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
          </div>
          <div class="crayon-plain-wrap">
           <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
            from threading import stack_size
stack_size(32768*16)
           </textarea>
          </div>
          <div class="crayon-main" style="">
           <table class="crayon-table">
            <tbody>
             <tr class="crayon-row">
              <td class="crayon-nums " data-settings="show">
               <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                <div class="crayon-num" data-line="crayon-5768659bc807a569365508-1">
                 1
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc807a569365508-2">
                 2
                </div>
               </div>
              </td>
              <td class="crayon-code">
               <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                <div class="crayon-line" id="crayon-5768659bc807a569365508-1">
                 <span class="crayon-e">
                  from
                 </span>
                 <span class="crayon-e">
                  threading
                 </span>
                 <span class="crayon-e">
                  import
                 </span>
                 <span class="crayon-e">
                  stack_size
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc807a569365508-2">
                 <span class="crayon-e">
                  stack_size
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-cn">
                  32768
                 </span>
                 <span class="crayon-o">
                  *
                 </span>
                 <span class="crayon-cn">
                  16
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
               </div>
              </td>
             </tr>
            </tbody>
           </table>
          </div>
         </div>
         <!-- [Format Time: 0.0021 seconds] -->
        </div>
       </div>
       <h3>
        <strong>
         3、设置失败后自动重试
        </strong>
       </h3>
       <div class="wp_syntax">
        <div class="code">
         <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
         <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-5768659bc8081549553146" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
          <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <span class="crayon-title">
           </span>
           <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
            <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-wrap-button" title="切换自动换行">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-expand-button" title="点击展开代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-copy-button" title="复制代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
           </div>
          </div>
          <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
          </div>
          <div class="crayon-plain-wrap">
           <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
            def get(self,req,retries=3):
        try:
            response = self.opener.open(req)
            data = response.read()
        except Exception , what:
            print what,req
            if retries&amp;gt;0:
                return self.get(req,retries-1)
            else:
                print 'GET Failed',req
                return ''
        return data
           </textarea>
          </div>
          <div class="crayon-main" style="">
           <table class="crayon-table">
            <tbody>
             <tr class="crayon-row">
              <td class="crayon-nums " data-settings="show">
               <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                <div class="crayon-num" data-line="crayon-5768659bc8081549553146-1">
                 1
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8081549553146-2">
                 2
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8081549553146-3">
                 3
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8081549553146-4">
                 4
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8081549553146-5">
                 5
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8081549553146-6">
                 6
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8081549553146-7">
                 7
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8081549553146-8">
                 8
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8081549553146-9">
                 9
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8081549553146-10">
                 10
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8081549553146-11">
                 11
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8081549553146-12">
                 12
                </div>
               </div>
              </td>
              <td class="crayon-code">
               <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                <div class="crayon-line" id="crayon-5768659bc8081549553146-1">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  def
                 </span>
                 <span class="crayon-e">
                  get
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-v">
                  req
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-v">
                  retries
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-cn">
                  3
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8081549553146-2">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  try
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8081549553146-3">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  response
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  opener
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  open
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  req
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8081549553146-4">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  data
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  response
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  read
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8081549553146-5">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  except
                 </span>
                 <span class="crayon-i">
                  Exception
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  what
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8081549553146-6">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  print
                 </span>
                 <span class="crayon-v">
                  what
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-e">
                  req
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8081549553146-7">
                 <span class="crayon-e">
                 </span>
                 <span class="crayon-st">
                  if
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  retries
                 </span>
                 <span class="crayon-o">
                  &amp;
                 </span>
                 <span class="crayon-v">
                  gt
                 </span>
                 <span class="crayon-sy">
                  ;
                 </span>
                 <span class="crayon-cn">
                  0
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8081549553146-8">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  return
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  get
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  req
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-v">
                  retries
                 </span>
                 <span class="crayon-o">
                  -
                 </span>
                 <span class="crayon-cn">
                  1
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8081549553146-9">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  else
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8081549553146-10">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-i">
                  print
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'GET Failed'
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-e">
                  req
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8081549553146-11">
                 <span class="crayon-e">
                 </span>
                 <span class="crayon-st">
                  return
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  ''
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8081549553146-12">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  return
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  data
                 </span>
                </div>
               </div>
              </td>
             </tr>
            </tbody>
           </table>
          </div>
         </div>
         <!-- [Format Time: 0.0060 seconds] -->
        </div>
       </div>
       <h3>
        <strong>
         4、设置超时
        </strong>
       </h3>
       <div class="wp_syntax">
        <div class="code">
         <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
         <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-5768659bc8089191265779" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
          <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <span class="crayon-title">
           </span>
           <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
            <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-wrap-button" title="切换自动换行">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-expand-button" title="点击展开代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-copy-button" title="复制代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
           </div>
          </div>
          <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
          </div>
          <div class="crayon-plain-wrap">
           <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
            import socket
    socket.setdefaulttimeout(10) #设置10秒后连接超时
           </textarea>
          </div>
          <div class="crayon-main" style="">
           <table class="crayon-table">
            <tbody>
             <tr class="crayon-row">
              <td class="crayon-nums " data-settings="show">
               <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                <div class="crayon-num" data-line="crayon-5768659bc8089191265779-1">
                 1
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8089191265779-2">
                 2
                </div>
               </div>
              </td>
              <td class="crayon-code">
               <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                <div class="crayon-line" id="crayon-5768659bc8089191265779-1">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  import
                 </span>
                 <span class="crayon-e">
                  socket
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8089191265779-2">
                 <span class="crayon-e">
                 </span>
                 <span class="crayon-v">
                  socket
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  setdefaulttimeout
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-cn">
                  10
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-p">
                  #设置10秒后连接超时
                 </span>
                </div>
               </div>
              </td>
             </tr>
            </tbody>
           </table>
          </div>
         </div>
         <!-- [Format Time: 0.0100 seconds] -->
        </div>
       </div>
       <h3>
        <strong>
         5、登陆
        </strong>
       </h3>
       <p>
        登陆更加简化了，首先build_opener中要加入cookie支持，参考“总结”一文；如要登陆VeryCD，给Fetcher新增一个空方法login，并在__init__()中调用，然后继承Fetcher类并override login方法：
       </p>
       <div class="wp_syntax">
        <div class="code">
         <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
         <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-5768659bc8090949505017" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
          <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <span class="crayon-title">
           </span>
           <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
            <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-wrap-button" title="切换自动换行">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-expand-button" title="点击展开代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-copy-button" title="复制代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
           </div>
          </div>
          <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
          </div>
          <div class="crayon-plain-wrap">
           <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
            def login(self,username,password):
    import urllib
    data=urllib.urlencode({'username':username,
                           'password':password,
                           'continue':'http://www.verycd.com/',
                           'login_submit':u'登录'.encode('utf-8'),
                           'save_cookie':1,})
    url = 'http://www.verycd.com/signin'
    self.opener.open(url,data).read()
           </textarea>
          </div>
          <div class="crayon-main" style="">
           <table class="crayon-table">
            <tbody>
             <tr class="crayon-row">
              <td class="crayon-nums " data-settings="show">
               <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                <div class="crayon-num" data-line="crayon-5768659bc8090949505017-1">
                 1
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8090949505017-2">
                 2
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8090949505017-3">
                 3
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8090949505017-4">
                 4
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8090949505017-5">
                 5
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8090949505017-6">
                 6
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8090949505017-7">
                 7
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-5768659bc8090949505017-8">
                 8
                </div>
                <div class="crayon-num" data-line="crayon-5768659bc8090949505017-9">
                 9
                </div>
               </div>
              </td>
              <td class="crayon-code">
               <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                <div class="crayon-line" id="crayon-5768659bc8090949505017-1">
                 <span class="crayon-e">
                  def
                 </span>
                 <span class="crayon-e">
                  login
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-v">
                  username
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-v">
                  password
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8090949505017-2">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  import
                 </span>
                 <span class="crayon-e">
                  urllib
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8090949505017-3">
                 <span class="crayon-e">
                 </span>
                 <span class="crayon-v">
                  data
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-v">
                  urllib
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  urlencode
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  {
                 </span>
                 <span class="crayon-s">
                  'username'
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                 <span class="crayon-v">
                  username
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8090949505017-4">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'password'
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                 <span class="crayon-v">
                  password
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8090949505017-5">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'continue'
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                 <span class="crayon-s">
                  'http://www.verycd.com/'
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8090949505017-6">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'login_submit'
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                 <span class="crayon-i">
                  u
                 </span>
                 <span class="crayon-s">
                  '登录'
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  encode
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-s">
                  'utf-8'
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8090949505017-7">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'save_cookie'
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                 <span class="crayon-cn">
                  1
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-sy">
                  }
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-5768659bc8090949505017-8">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  url
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'http://www.verycd.com/signin'
                 </span>
                </div>
                <div class="crayon-line" id="crayon-5768659bc8090949505017-9">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  opener
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  open
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  url
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-v">
                  data
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  read
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
               </div>
              </td>
             </tr>
            </tbody>
           </table>
          </div>
         </div>
         <!-- [Format Time: 0.0031 seconds] -->
        </div>
       </div>
       <p>
        于是在Fetcher初始化时便会自动登录VeryCD网站。
       </p>
       <h2>
        <span style="font-size: x-large;">
         四、总结
        </span>
       </h2>
       <p>
        如此，把上述所有小技巧都糅合起来就和我目前的私藏最终版的Fetcher类相差不远了，它支持多线程，gzip/deflate压缩，超时设置，自动重试，设置栈大小，自动登录等功能；代码简单，使用方便，性能也不俗，可谓居家旅行，杀人放火，咳咳，之必备工具。
       </p>
       <p>
        之所以说和最终版差得不远，是因为最终版还有一个保留功能“马甲术”：多代理自动选择。看起来好像仅仅是一个random.choice的区别，其实包含了代理获取，代理验证，代理测速等诸多环节，这就是另一个故事了。
       </p>
       <p>
       </p>
       <p>
        文章出处：
        <a href="http://obmem.info/?p=753" target="_blank">
         observer专栏杂记
        </a>
       </p>
      </div>
      <div>
       <strong>
        注：转载文章均来自于公开网络，仅供学习使用，不会用于任何商业用途，如果侵犯到原作者的权益，请您与我们联系删除或者授权事宜，联系邮箱：contact@dataunion.org。转载数盟网站文章请注明原文章作者，否则产生的任何版权纠纷与数盟无关。
       </strong>
      </div>
      <!--content_text-->
      <div class="fenxian">
       <!-- JiaThis Button BEGIN -->
       <div class="jiathis_style_32x32">
        <p class="jiathis_button_weixin">
        </p>
        <p class="jiathis_button_tsina">
        </p>
        <p class="jiathis_button_qzone">
        </p>
        <p class="jiathis_button_cqq">
        </p>
        <p class="jiathis_button_tumblr">
        </p>
        <a class="jiathis jiathis_txt jtico jtico_jiathis" href="http://www.jiathis.com/share" target="_blank">
        </a>
        <p class="jiathis_counter_style">
        </p>
       </div>
       <!-- JiaThis Button END -->
      </div>
     </article>
     <!--content-->
     <!--相关文章-->
     <div class="xianguan">
      <div class="xianguantitle">
       相关文章！
      </div>
      <ul class="pic">
       <li>
        <a href="http://dataunion.org/20820.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/09/1-300x200.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/20820.html" rel="bookmark" title="人们对Python在企业级开发中的10大误解">
         人们对Python在企业级开发中的10大误解
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/20587.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/08/t0192a35f52bc6e5eab-300x188.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/20587.html" rel="bookmark" title="基于Python的卷积神经网络和特征提取">
         基于Python的卷积神经网络和特征提取
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/20577.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/08/t01393a74373db553ec-300x206.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/20577.html" rel="bookmark" title="八大工具，透析Python数据生态圈最新趋势！">
         八大工具，透析Python数据生态圈最新趋势！
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/20544.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/08/t01f6b96e9cd9bae4d9_副本1-300x178.png"/>
        </a>
        <a class="link" href="http://dataunion.org/20544.html" rel="bookmark" title="python有哪些好的学习资料或者博客？">
         python有哪些好的学习资料或者博客？
        </a>
       </li>
      </ul>
     </div>
     <!--相关文章-->
     <div class="comment" id="comments">
      <!-- You can start editing here. -->
      <!-- If comments are open, but there are no comments. -->
      <div class="title">
       期待你一针见血的评论，Come on！
      </div>
      <div id="respond">
       <p>
        不用想啦，马上
        <a href="http://dataunion.org/wp-login.php?redirect_to=http%3A%2F%2Fdataunion.org%2F5230.html">
         "登录"
        </a>
        发表自已的想法.
       </p>
      </div>
     </div>
     <!-- .nav-single -->
    </div>
    <!--Container End-->
    <aside id="sitebar">
     <div class="sitebar_list2">
      <div class="wptag">
       <span class="tagtitle">
        热门标签+
       </span>
       <div class="tagg">
        <ul class="menu" id="menu-%e5%8f%8b%e6%83%85%e9%93%be%e6%8e%a5">
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1605" id="menu-item-1605">
          <a href="http://taidizh.com/">
           泰迪智慧
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20884" id="menu-item-20884">
          <a href="http://www.transwarp.cn/">
           星环科技
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-3538" id="menu-item-3538">
          <a href="http://datall.org/">
           珈和遥感
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20888" id="menu-item-20888">
          <a href="http://www.chinahadoop.cn/">
           小象学院
          </a>
         </li>
        </ul>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <div class="textwidget">
       <div align="center">
        <a href="http://study.163.com/course/courseMain.htm?courseId=991022" target="_blank">
         <img src="http://dataunion.org/wp-content/uploads/2016/03/dv.jpg"/>
        </a>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       文章分类
      </h4>
      <div class="tagcloud">
       <a class="tag-link-44" href="http://dataunion.org/category/industry/demo" style="font-size: 10.204724409449pt;" title="4个话题">
        Demo展示
       </a>
       <a class="tag-link-31" href="http://dataunion.org/category/experts" style="font-size: 15.826771653543pt;" title="52个话题">
        专家团队
       </a>
       <a class="tag-link-870" href="http://dataunion.org/category/tech/ai" style="font-size: 19.795275590551pt;" title="273个话题">
        人工智能
       </a>
       <a class="tag-link-488" href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f" style="font-size: 8pt;" title="1个话题">
        加入数盟
       </a>
       <a class="tag-link-869" href="http://dataunion.org/category/tech/viz" style="font-size: 17.204724409449pt;" title="93个话题">
        可视化
       </a>
       <a class="tag-link-30" href="http://dataunion.org/category/partners" style="font-size: 10.645669291339pt;" title="5个话题">
        合作伙伴
       </a>
       <a class="tag-link-889" href="http://dataunion.org/category/parterc" style="font-size: 11.582677165354pt;" title="8个话题">
        合作会议
       </a>
       <a class="tag-link-104" href="http://dataunion.org/category/books" style="font-size: 12.96062992126pt;" title="15个话题">
        图书
       </a>
       <a class="tag-link-220" href="http://dataunion.org/category/tech/base" style="font-size: 19.850393700787pt;" title="281个话题">
        基础架构
       </a>
       <a class="tag-link-219" href="http://dataunion.org/category/tech/analysis" style="font-size: 19.409448818898pt;" title="232个话题">
        数据分析
       </a>
       <a class="tag-link-887" href="http://dataunion.org/category/tech/dm" style="font-size: 13.291338582677pt;" title="17个话题">
        数据挖掘
       </a>
       <a class="tag-link-34" href="http://dataunion.org/category/tech" style="font-size: 20.732283464567pt;" title="404个话题">
        文章
       </a>
       <a class="tag-link-1" href="http://dataunion.org/category/uncategorized" style="font-size: 22pt;" title="693个话题">
        未分类
       </a>
       <a class="tag-link-4" href="http://dataunion.org/category/events" style="font-size: 14.503937007874pt;" title="29个话题">
        活动
       </a>
       <a class="tag-link-890" href="http://dataunion.org/category/tech/%e6%b7%b1%e5%ba%a6%e5%ad%a6%e4%b9%a0" style="font-size: 10.204724409449pt;" title="4个话题">
        深度学习
       </a>
       <a class="tag-link-221" href="http://dataunion.org/category/tech/devl" style="font-size: 18.968503937008pt;" title="193个话题">
        编程语言
       </a>
       <a class="tag-link-888" href="http://dataunion.org/category/career" style="font-size: 15.661417322835pt;" title="48个话题">
        职业规划
       </a>
       <a class="tag-link-5" href="http://dataunion.org/category/jobs" style="font-size: 14.11811023622pt;" title="25个话题">
        职位
       </a>
       <a class="tag-link-871" href="http://dataunion.org/category/industry" style="font-size: 15.716535433071pt;" title="49个话题">
        行业
       </a>
       <a class="tag-link-613" href="http://dataunion.org/category/industry/case" style="font-size: 16.984251968504pt;" title="84个话题">
        行业应用
       </a>
       <a class="tag-link-885" href="http://dataunion.org/category/industry/news" style="font-size: 17.425196850394pt;" title="102个话题">
        行业资讯
       </a>
       <a class="tag-link-10" href="http://dataunion.org/category/training" style="font-size: 14.228346456693pt;" title="26个话题">
        课程
       </a>
       <a class="tag-link-16" href="http://dataunion.org/category/sources" style="font-size: 15.661417322835pt;" title="48个话题">
        资源
       </a>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       功能
      </h4>
      <ul>
       <li>
        <a href="http://dataunion.org/wp-login.php?action=register">
         注册
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/wp-login.php">
         登录
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/feed">
         文章
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/comments/feed">
         评论
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="https://cn.wordpress.org/" title="基于WordPress，一个优美、先进的个人信息发布平台。">
         WordPress.org
        </a>
       </li>
      </ul>
     </div>
    </aside>
    <div class="clear">
    </div>
   </div>
   <!--main-->
   ﻿
   <footer id="dibu">
    <div class="about">
     <div class="right">
      <ul class="menu" id="menu-%e5%ba%95%e9%83%a8%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-18024" id="menu-item-18024">
        <a href="http://dataunion.org/category/partners">
         合作伙伴
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20881" id="menu-item-20881">
        <a href="http://dataunion.org/contribute">
         文章投稿
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20872" id="menu-item-20872">
        <a href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f">
         加入数盟
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22441" id="menu-item-22441">
        <a href="http://dataunion.org/f-links">
         友情链接
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20874" id="menu-item-20874">
        <a href="http://dataunion.org/aboutus">
         关于数盟
        </a>
       </li>
      </ul>
      <p class="banquan">
       数盟社区        ，
        做最棒的数据科学社区
      </p>
     </div>
     <div class="left">
      <ul class="bottomlist">
       <li>
        <a href="http://weibo.com/DataScientistUnion  " target="_blank" 　title="">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weibo.png"/>
        </a>
       </li>
       <li>
        <a class="cd-popup-trigger" href="http://dataunion.org/5230.html#0">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weixin.png"/>
        </a>
       </li>
      </ul>
      <div class="cd-popup">
       <div class="cd-popup-container">
        <h1>
         扫描二维码,加微信公众号
        </h1>
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/2014-12-06-1515289049.png"/>
        <a class="cd-popup-close" href="http://dataunion.org/5230.html">
        </a>
       </div>
       <!-- cd-popup-container -->
      </div>
      <!-- cd-popup -->
     </div>
    </div>
    <!--about-->
    <div class="bottom">
     <a href="http://dataunion.org/">
      数盟社区
     </a>
     <a href="http://www.miitbeian.gov.cn/" rel="external nofollow" target="_blank">
      京ICP备14026740号
     </a>
     联系我们：
     <a href="mailto:contact@dataunion.org" target="_blank">
      contact@dataunion.org
     </a>
     <div class="tongji">
     </div>
     <!--bottom-->
     <div class="scroll" id="scroll" style="display:none;">
      ︿
     </div>
    </div>
   </footer>
   <!--dibu-->
  </div>
 </body>
</html>